package com.platform.usercenter.domain.vo;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.platform.common.core.annotation.Excel;
import com.platform.common.core.domain.entity.SysDept;
import com.platform.common.core.web.domain.BaseEntity;
import com.platform.usercenter.domain.SysOrganization;
import com.platform.usercenter.domain.SysOrganizationDept;
import com.platform.usercenter.service.TreeAdapter;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 组织对象 sys_organization
 *
 * @author platform
 * @date 2024-10-24
 */
@Data
public class SysOrganizationVO implements TreeAdapter
{

    /** 组织ID */
    private Long orgId;

    /** 组织名称 */
    @Excel(name = "组织名称")
    private String orgName;

    /** 显示顺序 */
    @Excel(name = "显示顺序")
    private Long orderNum;

    /** 是否删除(Y,N) */
    @Excel(name = "是否删除(Y,N)")
    private String isDelete;

    /** 删除人 */
    @Excel(name = "删除人")
    private String deleteBy;

    /** 删除时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "删除时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date deleteTime;

    /** 负责人 */
    private String leader;

    /** 联系电话 */
    private String phone;

    /** 邮箱 */
    private String email;

    /** 组织状态:0正常,1停用 */
    private String status;

    /**
     * 父节点
     */
    private Long parentId;

    /** 子组织 */
    private List<SysOrganizationVO> children = new ArrayList<SysOrganizationVO>();

    /**
     * 部门集合
     */
    private List<SysDept> deptList;

    @Override
    public Long getTreeCurrentId() {
        return orgId;
    }

    @Override
    public Long getTreeParentId() {
        return parentId;
    }

    @Override
    public <T> void setTreeChildren(List<TreeAdapter> list, Class<T> clazz) {
        if (this.getClass().isAssignableFrom(clazz) && CollectionUtil.isNotEmpty(list)) {
            List<SysOrganizationVO> collect = list.stream().map(SysOrganizationVO.class::cast).collect(Collectors.toList());
            this.setChildren(collect);
        }
    }
}
